package com.zh.app.aop;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

//@Aspect
//@Component
public class LogInterceptor {
	
	private long cnt1;
	private long cnt2;
	
	//@Pointcut("execution(public * com.zh.app.service..*.*(..))")
	public void myMethod() {
		
	}
	
	//@Before("myMethod()")
	public void before() {
		System.out.println("method start");
		
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		System.out.println(df.format(date));
		cnt1 = date.getTime(); 
	}
	
	//@After("myMethod()")
	public void after() {
		System.out.println("method end");
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		Date date = new Date();
		System.out.println(df.format(date));
		cnt2 = date.getTime();
//		System.out.println(cnt2 - cnt1);
		
	}
	
	//@AfterReturning("myMethod()")
	public void afterReturn() {
		System.out.println("return method");		
	}
	
	//@Around("myMethod()")
	public void aroundMethod(ProceedingJoinPoint pjp) throws Throwable {
		System.out.println("around start");
		pjp.proceed();
		System.out.println("around end");	
	}
}
